#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
	char szT[1024];
	if (argc > 1)
	{
		strcpy(szT, argv[1]);
	}
	else
	{
		strcpy(szT, "a.docx");
	}
	
	FILE *fp = fopen(szT, "r+b");
	strcat(szT, ".c");
	FILE *fp2 = fopen(szT, "wt");
	if (fp != NULL && fp2 != NULL )
	{
		fseek(fp, 0, SEEK_END);
		int nT = ftell(fp);
		fseek(fp, 0, SEEK_SET);
		fprintf(fp2, "const unsigned char g_ucT[%d]={\n\t", nT);
		nT = 0;
		while (!feof(fp))
		{
			unsigned char c = getc(fp);
			fprintf(fp2, "0x%02X,", c);
			if (((nT++)&0x0F) == 0x0F)
			{
				fprintf(fp2, "\n\t");
			}
		}
		//文件结尾（英语：End of File，缩写为EOF）通常是-1，unsigned char的0xFF,所以要回退6或8个字节
		if (nT > 5)
		{
			nT = (nT & 0x0F) == 0x01 ? -8 : -6;
			fseek(fp2, nT, SEEK_CUR);
		}
		
		fprintf(fp2, "\n};\n\n\n\n\n");
		fclose(fp);
		fclose(fp2);
	}
	return 0;
}
